﻿using Microsoft.Extensions.DependencyInjection;
using MinimalWinFormiumApp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinFormium.JavaScript;
using WinFormium.WebResource;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace WinFormium.cs
{
    class MyApp : WinFormiumStartup
    {
        protected override MainWindowCreationAction? UseMainWindow(MainWindowOptions opts)
        {
            // 设置应用程序的主窗体
            return opts.UseMainFormium<MyWindow>();
        }

        protected override void WinFormiumMain(string[] args)
        {
            // Main函数中的代码应该在这里，该函数只在主进程中运行。这样可以防止子进程运行一些不正确的初始化代码。
            ApplicationConfiguration.Initialize();
        }

        protected override void ConfigurationChromiumEmbedded(ChromiumEnvironmentBuiler cef)
        {
            // 在此处配置 Chromium Embedded Framwork
        }

        protected override void ConfigureServices(IServiceCollection services)
        {
            // 在这里配置该应用程序的服务
            // 注册嵌入资源
            //services.AddEmbeddedFileResource(new EmbeddedFileResourceOptions
            //{
            //    Scheme = "http",
            //    DomainName = "embedded.app.local",
            //    ResourceAssembly = typeof(Program).Assembly,
            //    EmbeddedResourceDirectoryName = "wwwroot",
            //});

            // 注册本地资源
            services.AddLocalFileResource(new LocalFileResourceOptions
            {
                Scheme = "http",
                DomainName = "files.app.local",
                PhysicalFilePath = Path.Combine(AppContext.BaseDirectory, "wwwroot"),
            });

            string a = AppContext.BaseDirectory;

            // 注册 JavaScript Window Binding Object
            services.AddWindowBindingObject<TestWindowBindingObject>();
        }
    }
}
